package com.ruoyi.project.system.service.impl;

import com.ruoyi.project.system.domain.SysOrderDetail;
import com.ruoyi.project.system.mapper.SysOrderDetailDao;
import com.ruoyi.project.system.service.SysOrderDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (SysOrderDetail)表服务实现类
 *
 * @author makejava
 * @since 2020-02-23 13:40:14
 */
@Service
public class SysOrderDetailServiceImpl implements SysOrderDetailService {
    @Resource
    private SysOrderDetailDao sysOrderDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param detailId 主键
     * @return 实例对象
     */
    @Override
    public SysOrderDetail queryById(Long detailId) {
        return this.sysOrderDetailDao.queryById(detailId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<SysOrderDetail> queryAllByLimit(int offset, int limit) {
        return this.sysOrderDetailDao.queryAllByLimit(offset, limit);
    }

    @Override
    public List<SysOrderDetail> queryByOrderId(Long orderId) {
        return this.sysOrderDetailDao.queryByOrderId(orderId);
    }

    /**
     * 新增数据
     *
     * @param sysOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public SysOrderDetail insert(SysOrderDetail sysOrderDetail) {
        this.sysOrderDetailDao.insert(sysOrderDetail);
        return sysOrderDetail;
    }

    /**
     * 修改数据
     *
     * @param sysOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public SysOrderDetail update(SysOrderDetail sysOrderDetail) {
        this.sysOrderDetailDao.update(sysOrderDetail);
        return this.queryById(sysOrderDetail.getDetailId());
    }

    /**
     * 通过主键删除数据
     *
     * @param detailId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long detailId) {
        return this.sysOrderDetailDao.deleteById(detailId) > 0;
    }
}